package org.snail.attendence.controller;

import lombok.NonNull;
import lombok.extern.log4j.Log4j;
import org.snail.attendence.bean.AttCheckCondition;
import org.snail.attendence.bean.AttendanceCheckDO;
import org.snail.attendence.service.impl.AttendanceCheckServiceImpl;
import org.snail.exception.CommonException;
import org.snail.exception.EmpException;
import org.snail.exception.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("attendenceCheck")
@Log4j
public class AttendenceCheckController {
    @Autowired
    public AttendanceCheckServiceImpl attendanceCheckService;

    /**
     * 最终考勤
     * @param
     * @return
     * @throws EmpException
     */
    @RequestMapping("/countAttendance")
    @ResponseBody
    public JsonResult finalAttendance(@NonNull AttCheckCondition attCheckCondition){
        JsonResult jsonResult = new JsonResult();
        AttendanceCheckDO attendanceCheckDO = attendanceCheckService.countAttendance(attCheckCondition);
        jsonResult.setCode(200);
        jsonResult.setData(attendanceCheckDO);
        return jsonResult;

    }

    /**
     * 核算
     * @param
     * @return
     * @throws EmpException
     */
    @RequestMapping("/countAndClearAtt")
    @ResponseBody
    public JsonResult countAndClearAtt(@NonNull AttendanceCheckDO attCheckCondition) throws CommonException {
        JsonResult jsonResult = new JsonResult();
        attendanceCheckService.countAndClearAtt(attCheckCondition);
        jsonResult.setCode(200);
        return jsonResult;

    }

    /**
     * 考勤核算历史记录
     * @param
     * @return
     * @throws EmpException
     */
    @RequestMapping("/findAttHistoryList")
    @ResponseBody
    public JsonResult checkAttList(@NonNull AttCheckCondition attCheckCondition){
        JsonResult jsonResult = new JsonResult();
        List<AttendanceCheckDO> attHistoryList = attendanceCheckService.findAttHistoryList(attCheckCondition);
        jsonResult.setCode(200);
        jsonResult.setData(attHistoryList);
        return jsonResult;
    }


    /**
     * 测试用
     *
     * @param
     * @return
     * @throws EmpException
     */
    @RequestMapping("/test")
    @ResponseBody
    public void test(AttCheckCondition attCheckCondition) {
        attendanceCheckService.test(attCheckCondition);
    }

}
